﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Expect.Core.Interfaces;
using System.Globalization;

namespace Expect.Documentation.TypeConverters
{    
    public class PriceConverter : IExpectTypeConverter<Price>
    {
        #region IExpectTypeConverter Members

        public object Convert(string text)
        {
            var price = new Price();
            text = text.Trim();
            if (!string.IsNullOrEmpty(text))
            {
                int idx = text.LastIndexOf(' ');
                if (idx <= 0)
                    throw new ArgumentException("The param " + text + " is not a valid price");
                var parts = text.Split(' ');
                price.Amount = System.Convert.ToDouble(text.Substring(0, idx), new CultureInfo("fr-FR"));
                price.Currency = text.Substring(idx+1);
            }
            return price;
        }

        #endregion
    }
}
